/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain an copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.slice.picker;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;

import com.xuexiang.xuidemo.ResourceTable;

public class PickerAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private Image imageBack;
    private DirectionalLayout dl_one, dl_two, dl_three, dl_four, dl_five;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_picker);
        initComponent();
        initClickedListener();
    }

    public void initComponent() {
        imageBack = (Image) findComponentById(ResourceTable.Id_image_back);
        dl_one = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_one);
        dl_two = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_two);
        dl_three = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_three);
        dl_four = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_four);
        dl_five = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_five);
    }

    private void initClickedListener() {
        imageBack.setClickedListener(this);
        dl_one.setClickedListener(this);
        dl_two.setClickedListener(this);
        dl_three.setClickedListener(this);
        dl_four.setClickedListener(this);
        dl_five.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_image_back:
                onBackPressed();
                break;
            case ResourceTable.Id_dl_one:
                // 时间选择器
                present(new TimePickerAbilitySlice(), new Intent());
                break;
            case ResourceTable.Id_dl_two:
                // 三级选择器
                present(new AddressPickerAbilitySlice(), new Intent());
                break;
            case ResourceTable.Id_dl_three:
                present(new OptionsPickerAbilitySlice(), new Intent());
                break;
            case ResourceTable.Id_dl_four:
                present(new RulerViewSlice(), new Intent());
                break;
            case ResourceTable.Id_dl_five:
                present(new SeekBarAbilitySlice(), new Intent());
                break;
        }
    }
}
